#define BOOST_TEST_MODULE rsa

#include "../otpch.h"

#include "../tools.h"

#include <boost/test/unit_test.hpp>

using namespace std::string_view_literals;

struct SHA1Fixture
{
	std::string_view input;
	std::string_view expected;
};

// test vectors from https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing
// up to 64 bytes in input length
auto testVectors = std::vector<SHA1Fixture>{
    {.input = "", .expected = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18\x90\xaf\xd8\x07\x09"sv},
    {.input = "\x36", .expected = "\xc1\xdf\xd9\x6e\xea\x8c\xc2\xb6\x27\x85\x27\x5b\xca\x38\xac\x26\x12\x56\xe2\x78"sv},
    {.input = "\x19\x5a",
     .expected = "\x0a\x1c\x2d\x55\x5b\xbe\x43\x1a\xd6\x28\x8a\xf5\xa5\x4f\x93\xe0\x44\x9c\x92\x32"sv},
    {.input = "\xdf\x4b\xd2",
     .expected = "\xbf\x36\xed\x5d\x74\x72\x7d\xfd\x5d\x78\x54\xec\x6b\x1d\x49\x46\x8d\x8e\xe8\xaa"sv},
    {.input = "\x54\x9e\x95\x9e",
     .expected = "\xb7\x8b\xae\x6d\x14\x33\x8f\xfc\xcf\xd5\xd5\xb5\x67\x4a\x27\x5f\x6e\xf9\xc7\x17"sv},
    {.input = "\xf7\xfb\x1b\xe2\x05",
     .expected = "\x60\xb7\xd5\xbb\x56\x0a\x1a\xcf\x6f\xa4\x57\x21\xbd\x0a\xbb\x41\x9a\x84\x1a\x89"sv},
    {.input = "\xc0\xe5\xab\xea\xea\x63",
     .expected = "\xa6\xd3\x38\x45\x97\x80\xc0\x83\x63\x09\x0f\xd8\xfc\x7d\x28\xdc\x80\xe8\xe0\x1f"sv},
    {.input = "\x63\xbf\xc1\xed\x7f\x78\xab",
     .expected = "\x86\x03\x28\xd8\x05\x09\x50\x0c\x17\x83\x16\x9e\xbf\x0b\xa0\xc4\xb9\x4d\xa5\xe5"sv},
    {.input = "\x7e\x3d\x7b\x3e\xad\xa9\x88\x66",
     .expected = "\x24\xa2\xc3\x4b\x97\x63\x05\x27\x7c\xe5\x8c\x2f\x42\xd5\x09\x20\x31\x57\x25\x20"sv},

};

BOOST_AUTO_TEST_CASE(test_sha1)
{
	for (auto&& [input, expected] : testVectors) {
		std::string result = transformToSHA1(input);
		BOOST_TEST(result == expected, "expected '" << expected << "', got '" << result << "'");
	}
}
